package com.zhaorujie.rpc.demo.client.controller;

import cn.hutool.json.JSONUtil;
import com.zhaorujie.rpc.core.remoting.invoker.annotain.RpcReference;
import com.zhaorujie.rpc.demo.api.DemoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 赵汝杰
 * @version v1.0
 * @description DemoController
 * @date 2024/3/6
 **/
@RestController
@RequestMapping("/demo")
public class DemoController {


    @RpcReference(timeout = 3000)
    private DemoService demoService;

    @GetMapping("/test")
    public String test() {
        Map<String, Object> result = new HashMap<>();
        try {
            result.put("result", demoService.rpcRemote());
        } catch (Exception e) {
            e.printStackTrace();
            return e.getMessage();
        }
        return JSONUtil.toJsonStr(result);
    }
}
